<template>
  <div class="con">
    <div>
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <!-- :to="{ path: '/' }" -->
        <div class="div1">
          <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item class="dangqian">搜索</el-breadcrumb-item>
        </div>

        <div class="div2">
          <div class="div_1" v-if="i_Hidden" @click="active_i">
            <i class="el-icon-bottom"></i>
            <i class="el-icon-bottom"></i>
          </div>

          <div class="div_2" v-else @click="active_i">
            <i class="el-icon-right"></i>
            <i class="el-icon-right"></i>
          </div>
        </div>
      </el-breadcrumb>
      <div class="right1">
        <div class="list" v-if="hidden">
          <!-- <div class="item"
               v-for="(item,index) in goods"
               :key="index"
               @click="linkdetil(item.id)">
            <img class="img"
                 :src="item.imgurl||item.img"
                 alt="" />
            <div class="one oneline">{{item.name}}</div>
            <div class="img threeline img-add"
                 v-if="item.category==1">{{item.title}}</div>
            <div v-if="select=='0'"
                 class="two">￥<span>{{item.price?item.price.toFixed(2):'????'}}</span>
            </div>
          </div> -->
          <div
            v-for="items in goods"
            :key="items.index"
            class="list1"
            @click="linkgoods(items.goodsId || items.id)"
          >
            <img :src="items.imgurl || items.img" class="img" />
            <div class="name">
              <div class="one" :class="{ one1: select == '0' }">
                {{ items.name }}
              </div>
              <div v-if="select == '0'" class="to">
                <span>￥</span>{{ items.price }}
              </div>
              <div class="zhifu">
                <img
                  v-if="items.shopTag == 1"
                  src="@/assets/img/dianpu/zhiying.png"
                  alt=""
                />
              </div>
            </div>
          </div>
        </div>

        <div class="listTo" v-else>
          <!-- <div class="item"
               v-for="(item,index) in goods"
               :key="index"
               @click="linkdetil(item.id)">
            <img class="img"
                 :src="item.imgurl||item.img"
                 alt="" />
            <div class="one oneline">{{item.name}}</div>
            <div class="img threeline img-add"
                 v-if="item.category==1">{{item.title}}</div>
            <div v-if="select=='0'"
                 class="two">￥<span>{{item.price?item.price.toFixed(2):'????'}}</span>
            </div>
          </div> -->
          <div
            v-for="items in goods"
            :key="items.index"
            class="list1"
            @click="linkgoods(items.goodsId || items.id)"
          >
            <img :src="items.imgurl || items.img" class="img" />
            <div class="name">
              <div class="one" :class="{ one1: select == '0' }">
                {{ items.name }}
              </div>
              <div v-if="select == '0'" class="to">
                <span>￥</span>{{ items.price }}
              </div>
              <div class="zhifu">
                <img
                  v-if="items.shopTag == 1"
                  src="@/assets/img/dianpu/zhiying.png"
                  alt=""
                />
              </div>
            </div>
          </div>
        </div>
      </div>

      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :current-page.sync="pageNum"
        :page-size="pageSize"
        @current-change="handleCurrentChange"
        prev-text="上一页"
        next-text="下一页"
        class="aut"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      goods: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      name: "",
      select: "",
      hidden: true,
      i_Hidden: true
    };
  },
  //注册组件
  components: {},
  //生命周期 - 创建完成（访问当前this实例）
  created() {
    this.isinput();
    this.route();
    this.getgoods();
  },
  watch: {
    $route(to, from) {
      //刷新参数放到这里里面去触发就可以刷新相同界面了
      if (to.path.indexOf("search") > 0) {
        this.route();
        this.getgoods();
      }
    }
  },
  methods: {
    active_i() {
      this.hidden = !this.hidden;
      this.i_Hidden = !this.i_Hidden;
    },
    route() {
      this.name = this.$route.query.name;
      this.select = this.$route.query.select;
    },
    isinput() {
      this.$store.commit("setDValue", true);
    },
    async getgoods() {
      if (this.select == "0") {
        let response = await this.$postRequest("/api/goods/findGoods", {
          name: this.name,
          pageNum: this.pageNum,
          pageSize: 10,
          userId: localStorage.getItem("userId")
        });
        for (let i of response.data.list) {
          i.value = i.name; //将想要展示的数据作为value
        }
        this.goods = response.data.list;
        console.log(this.goods);
      } else {
        let response = await this.$postRequest("/api/goods/searchShop", {
          name: this.name,
          pageNum: this.pageNum,
          pageSize: 10,
          userId: localStorage.getItem("userId")
        });
        console.log(response);
        for (let i of response.data) {
          i.value = i.name; //将想要展示的数据作为value
        }
        this.goods = response.data;
      }
      console.log(this.goods);
    },
    // 分页
    handleCurrentChange(currentPage) {
      this.getgoods();
    },
    linkgoods(id) {
      if (this.select == "0") {
        let Detail = this.$router.resolve({
          path: "/home/detail",
          query: { id }
        });
        window.open(Detail.href, "_blank");
      } else {
        this.$router.push({ path: "/home/business", query: { id } });
      }
    }
  }
};
</script>
<style scoped lang='scss'>
.con {
  background-color: #f9f9f9;
  & > div {
    width: 1400px;
    margin: auto;
    /deep/ .el-breadcrumb {
      position: relative;
      display: flex;
      align-items: center;
      width: 100%;
      height: 48px;
      font-size: 14px;
      line-height: 48px;
      .div2 {
        position: absolute;
        left: 180px;
        .div_2 {
          display: flex;
          flex-direction: column;
          align-items: center;
        }
      }
      .el-breadcrumb__inner {
        color: #999;
        font-weight: 500;
      }
      .dangqian .el-breadcrumb__inner {
        color: #1a69e0;
      }
    }
    .right1 {
      width: 100%;
      background: #ffffff;
      border: 1px solid #eeeeee;
      margin-bottom: 20px;
      .shang {
        .shangpin {
          width: 100%;
          height: 190px;
          background: #ffffff;
          border-bottom: 1px solid #eeeeee;
          display: flex;
          padding: 20px;
          .shab {
            width: 150px;
            height: 150px;
            background: #ffffff;
            border: 1px solid #f9f9f9;
            margin-right: 20px;
          }
          .right2 {
            width: 100%;
            .one {
              font-size: 16px;
              font-family: Microsoft YaHei;
              font-weight: 400;
              color: #000000;
              margin-top: 10px;
            }
            .two {
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: 500;
              color: #747474;
              margin: 18px 0;
            }
            .shw {
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: bold;
              color: #e0441a;
              margin-bottom: 18px;
              span {
                font-size: 24px;
              }
            }
            .si {
              font-size: 16px;
              font-family: PingFang SC;
              font-weight: 500;
              color: #666666;
            }
          }
        }
        .xuqiu {
          width: 100%;
          background: #ffffff;
          border-bottom: 1px solid #eeeeee;
          padding: 20px;
          cursor: pointer;
          .one {
            font-size: 16px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #000000;
            margin-bottom: 10px;
          }
          .two {
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #666666;
            line-height: 20px;
            margin-bottom: 10px;
          }
          .shw {
            height: 14px;
            font-size: 14px;
            font-family: PingFang SC;
            font-weight: 500;
            color: #999999;
            line-height: 20px;
            & > span {
              margin-right: 30px;
              & > span {
                color: #e0441a;
              }
            }
          }
        }
      }
      .aut {
        text-align: center;
        margin-top: 14px;
      }
    }
  }
  /deep/ .el-pagination {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
    button,
    .el-pagination span:not([class*="suffix"]) {
      width: 60px;
    }
  }
  .list {
    display: flex;
    flex-wrap: wrap;
    .list1 {
      width: 210px;
      margin-left: 20px;
      margin-bottom: 20px;
      cursor: pointer;
      .img {
        width: 210px;
        height: 210px;
      }
      .name {
        position: relative;
        width: 210px;
        height: 70px;
        background: #ffffff;
        // border: 1px solid #f9f9f9;
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        .one {
          height: 30px;
          line-height: 30px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .to {
          height: 30px;
          line-height: 30px;
          color: #e0441a;
          font-family: PingFang SC;
          font-weight: bold;
          font-size: 24px;
          span {
            font-size: 16px;
          }
        }
        .zhifu {
          position: absolute;
          right: 0;
          bottom: 12px;
          img {
            width: 32px;
            height: 18px;
          }
        }
      }
    }
  }
  .listTo {
    .list1 {
      display: flex;
      align-items: center;
      width: 210px;
      margin-left: 20px;
      margin-bottom: 20px;
      cursor: pointer;
      margin-bottom: 1px solid #ccc;
      .img {
        width: 210px;
        height: 210px;
        margin-right: 30px;
      }
      .name {
        position: relative;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 120px;
        background: #ffffff;
        // border: 1px solid #f9f9f9;
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #000000;
        .one {
          height: 30px;
          line-height: 30px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .to {
          height: 30px;
          line-height: 30px;
          color: #e0441a;
          font-family: PingFang SC;
          font-weight: bold;
          font-size: 24px;
          span {
            font-size: 16px;
          }
        }
        .zhifu {
          position: absolute;
          img {
            width: 30px;
            height: 18px;
          }
        }
      }
    }
  }
}
</style>